package logic

import (
	"context"
	"fresh-box-manage/models/mysql"

	"fresh-box-manage/freshrpc/freshrpc"
	"fresh-box-manage/freshrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type FreshShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFreshShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FreshShowLogic {
	return &FreshShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *FreshShowLogic) FreshShow(in *freshrpc.FreshShowRequest) (*freshrpc.FreshShowResponse, error) {
	// todo: add your logic here and delete this line

	var fresh mysql.Fresh

	if err := fresh.FreshFindById(mysql.DB, in.FreshId); err != nil {
		return nil, err
	}

	return &freshrpc.FreshShowResponse{
		FreshId: int64(fresh.ID),
		Name:    fresh.Name,
		Price:   float32(fresh.Price),
		Num:     int64(fresh.Num),
	}, nil
}
